package com.myproject.mall.announcement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.myproject.mall.announcement.mapper.AnnouncementMapper;
import com.myproject.mall.announcement.service.IAnnouncementService;
import com.myproject.mall.domain.entity.Announcement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AnnouncementServiceImpl implements IAnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public List<Announcement> getAll() {
        return announcementMapper.selectList(null);
    }

    @Override
    public List<Announcement> getByStatus(Integer status) {
        return announcementMapper.selectList(new LambdaQueryWrapper<Announcement>().eq(Announcement::getStatus, status));
    }

    @Transactional
    @Override
    public void addAnnouncement(Announcement announcement) {
        announcementMapper.insert(announcement);
    }

    @Transactional
    @Override
    public void updateAnnouncement(Announcement announcement) {
        announcementMapper.updateById(announcement);
    }
}
